<?php defined('BASEPATH') OR exit('No direct script access allowed');


class Role_menu_model extends Base_model
{
	protected $_table_name = 'role_menu';
    protected $_key_name = 'id';
	
	public function __construct()
    {
        parent::__construct();
		log_message("debug","role_menu_model");
    }

    public function dels($id = 0)
    {
        if($id <= 0) return false;
        return $this->delete(array("role_id"=>$id));
    }

    public function adds($data_arr = NULL)
    {
        if($data_arr == NULL) return false;

        $add_arr = NULL;
        foreach($data_arr as $val)
        {
            $zi["role_id"] = $val["roleId"];
            $zi["menu_id"] = $val["menuId"];
            $zi["ctime"] = time();
            $add_arr[] = $zi;
        }
        //$data_arr["ctime"] = time();
        return $this->insert_batch($add_arr);
    }

    public function get_menu_all($id = 0)
    {
        $this->select("menu.id as id,name,parent_id as parentId,url,perms,type,icon,order_num as orderNum ");
        $this->join('menu','menu.id = role_menu.menu_id','left');
        $this->where("role_menu.role_id",$id);
        return $this->all();
    }


    public function get_menu_id_by_role_ids($ids = NULL)
    {
        $this->select("menu_id");
        $this->where_in("role_id",$ids);
        return $this->all();
    }
	
}
/* End of file base_model.php */
/* Location: ./system/application/models/base_model.php */
